package com.tfswx.ruleengine.compute.util;

import com.tfswx.ruleengine.compute.exception.AppException;
import org.springframework.core.io.ClassPathResource;
import org.yaml.snakeyaml.Yaml;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;

/**
 * @author Ricky
 * @date 2021/7/14
 */
public class TyywTableNameUtil {
    private TyywTableNameUtil() {
    }

    private static final List<String> tyywTableNameList;

    static {
        Yaml yaml = new Yaml();
        ClassPathResource classPathResource = new ClassPathResource("data/tyywTable.yml");
        try (InputStream is = classPathResource.getInputStream()) {
            Map<String, List<String>> map = yaml.loadAs(is, Map.class);
            tyywTableNameList = map.get("tyywTableNameList");
        } catch (FileNotFoundException e) {
            throw new AppException("文件没有找到", e);
        } catch (IOException e) {
            throw new AppException("文件加载异常", e);
        }
    }

    public static boolean isTyywTable(String stbm) {
        return tyywTableNameList.contains(stbm);
    }
}
